<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "zjfl".
 *
 * @property integer $id
 * @property string $stu_id
 * @property string $before_major
 * @property string $after_major
 * @property string $befor_class
 * @property string $after_class
 */
class Zjfl extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'zjfl';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['stu_id','name', ], 'required'],
            [['name','stu_id', 'before_major', 'after_major', 'befor_class', 'after_class'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'stu_id' => '学号',
        		'name'=>'姓名',
            'before_major' => '原专业',
            'after_major' => '现专业',
            'befor_class' => '原班级',
            'after_class' => '现班级',
        ];
    }


    /**
     * 保存导入excel文件内容
     * @param $data  传入文件内容的数组
     * @return bool  保存成功返回true
     *
     */
    public static function SaveImport($data){

        try{
            foreach ($data as $value){
                $person=new Zjfl();
                $person->stu_id=$value['学号'].'';//学号要转化为字符型才能通过验证
                $person->name=$value['姓名'].'';
                $person->before_major=$value['原专业'].'';
                $person-> after_major=$value['现专业'].'';
                $person->befor_class=$value['原班级'].'';
                $person->after_class=$value['现班级'].'';

                $person->save();
            }
            return true;

        }catch (\Exception $e){
            throw $e;
        }

    }

}
